/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.display;

import plash.utils.ColorMapper;
import processing.core.PGraphics;

/**
 *
 * @author  #0K Srinivasan <hashok.com>
 */
public class GraphicFill implements IGraphicCommand
{

    protected Graphics __g;
    protected PGraphics _painter;
    protected float _alpha;
    private ColorMapper _cmapper;

    public GraphicFill(Graphics g, int rgb, float alpha)
    {
        __g = g;
        _painter = g.getPainter();
        _cmapper = new ColorMapper(alpha, rgb);
        _alpha = alpha;
    }

    @Override
    public void execute()
    {
        if (__g == null)
        {
            return;
        }
        if(__g.getOwner().getPainter() == null)
        {
            return;
        }
        if (_cmapper.getAlpha() == 0)
        {
            __g.getOwner().getPainter().noFill();
            return;
        }
        __g.getOwner().getPainter().fill(_cmapper.getRed(), _cmapper.getGreen(), _cmapper.getBlue(), _cmapper.getAlpha() * __g.getOwner().getAlpha());       
    }
}